package com.stary.springmvc.web.viewResolver;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.view.AbstractView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**             自定义视图
 *  解读：
 *   1.MyView继承了AbstractView，可以作为一个视图使用
 *   2.@Component，该视图会作为一个组件注入到容器中，id值为hspView
 */
@Component("hspView")
public class MyView extends AbstractView {
    @Override
    protected void renderMergedOutputModel(Map<String, Object> map, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
        System.out.println("进入到视图页面");
        //完成视图渲染
        //我们要跳转的页面[请求转发的方式]/WEB-INF/pages/my_view.jsp
        // /WEB-INF/pages/my_view.jsp会被springmvc解析——/WEB-INF/会被解析成项目路径
        //最终被解析成 /day10_SpringMVC_war_exploded/pages/my_view.jsp
        httpServletRequest.getRequestDispatcher("/WEB-INF/pages/my_view.jsp").forward(httpServletRequest,httpServletResponse);
    }
}
